<template>
  <a-card class="j-inner-table-wrapper" :bordered="false">

    <!-- 查询区域 begin -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="财务组织">
              <j-dict-select-tag v-model="queryParam.paymentCompany" placeholder="请选择付款单位" dictCode="DataDictionary,description,dictionaryCode, dictionaryTypeId = COSTPAYMENT_TYPE"/>
        </a-form-item>
      </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="单据日期">
          <j-date class="query-group-cust" v-model="queryParam.billdate_fld0_value" placeholder="请选择开始日期"/>
          <span class="query-group-split-cust"></span>
          <j-date class="query-group-cust" v-model="queryParam.billdate_fld1_value" placeholder="请选择结束日期"/>
        </a-form-item>
      </a-col>
          <template v-if="toggleSearchStatus">
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="起算日期">
            <j-date class="query-group-cust" v-model="queryParam.busidate_fld0_value" placeholder="请选择开始日期"/>
            <span class="query-group-split-cust"></span>
            <j-date class="query-group-cust" v-model="queryParam.busidate_fld1_value" placeholder="请选择结束日期"/>
          </a-form-item>
        </a-col>
          </template>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span class="table-page-search-submitButtons table-operator">
              <a-button type="primary" icon="search" @click="searchQuery">查询</a-button>
              <a-button type="primary" icon="reload" @click="searchReset">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                <span>{{ toggleSearchStatus ? '收起' : '展开' }}</span>
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域 end -->

    <!-- 操作按钮区域 begin -->
    <div class="table-operator">
      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
        <a-button type="primary" icon="import">导入</a-button>
      </a-upload>
      <a-button type="primary" icon="download"   @click="handleExportXlsTemplate('预估收款单','images/model/clmCollectionOrderList.xls')" >下载模板</a-button>
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel">
            <a-icon type="delete"/>
            <span>删除</span>
          </a-menu-item>
        </a-menu>
        <a-button>
          <span>批量操作</span>
          <a-icon type="down"/>
        </a-button>
      </a-dropdown>
    </div>
    <!-- 操作按钮区域 end -->

    <!-- table区域 begin -->
    <div>

      <a-alert type="info" showIcon style="margin-bottom: 16px;">
        <template slot="message">
          <span>已选择</span>
          <a style="font-weight: 600;padding: 0 4px;">{{ selectedRowKeys.length }}</a>
          <span>项</span>
          <a style="margin-left: 24px" @click="onClearSelected">清空</a>
        </template>
      </a-alert>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        class="j-table-force-nowrap"
        :loading="loading"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :expandedRowKeys="expandedRowKeys"
        :rowSelection="{selectedRowKeys, onChange: onSelectChange}"
        @expand="handleExpand"
        @change="handleTableChange"
      >

        <!-- 内嵌table区域 begin -->
        <template slot="expandedRowRender" slot-scope="record">
          <a-tabs tabPosition="top">
            <a-tab-pane tab="明细" key="clmCollectionItem" forceRender>
              <clm-collection-item-sub-table :record="record"/>
            </a-tab-pane>
          </a-tabs>
        </template>
        <!-- 内嵌table区域 end -->

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>

        <template slot="imgSlot" slot-scope="text">
          <div style="font-size: 12px;font-style: italic;">
            <span v-if="!text">无图片</span>
            <img v-else :src="getImgView(text)" alt="" style="max-width:80px;height:25px;"/>
          </div>
        </template>

        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            ghost
            type="primary"
            icon="download"
            size="small"
            @click="uploadFile(text)"
          >
            <span>下载</span>
          </a-button>
        </template>

        <template slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)"  v-if="record.isSyncNc !='Y'">编辑</a>
          <a-divider type="vertical" v-if="record.isSyncNc !='Y'"/>
          <a-dropdown>
            <a class="ant-dropdown-link">
              <span>更多 <a-icon type="down"/></span>
            </a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="handleView(record)">查看</a>
              </a-menu-item>
              <a-menu-item v-if="record.isSyncNc !='Y'">
                <a-popconfirm title="确定同步吗?" @confirm="() => handleConfim(record.id)">
                  <a>同步用友</a>
                </a-popconfirm>
              </a-menu-item>
              <a-menu-item v-if="record.isSyncNc !='Y'">
                <a-popconfirm title="确定删除吗?" @confirm="handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>

        </template>

      </a-table>
    </div>
    <!-- table区域 end -->

    <!-- 表单区域 -->
    <clm-collection-order-modal ref="modalForm" @ok="modalFormOk"/>

  </a-card>
</template>

<script>
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import ClmCollectionOrderModal from './modules/ClmCollectionOrderModal'
  import ClmCollectionItemSubTable from './subTables/ClmCollectionItemSubTable'
  import JDictSelectTag from '@/components/dict/JDictSelectTag.vue'
  import JDate from '@/components/jeecg/JDate.vue'
  import {filterMultiDictText} from '@/components/dict/JDictSelectUtil'
  import '@/assets/less/TableExpand.less'
  import {getAction,postAction} from '@/api/manage'


  export default {
    name: 'ClmCollectionOrderList',
    mixins: [JeecgListMixin],
    components: {
      ClmCollectionOrderModal,
      ClmCollectionItemSubTable,
      JDate,
      JDictSelectTag,
    },
    data() {
      return {
        description: '发票列表管理页面',
	      dataParam: {
           billdate_fld0_op:"greaterThanEqualTo",
           billdate_fld1_op:"lessThanEqualTo",
           busidate_fld0_op:"greaterThanEqualTo",
           busidate_fld1_op:"lessThanEqualTo",
        },
        // 表头
        columns: [
          {
            title: '#',
            key: 'rowIndex',
            width: 60,
            align: 'center',
            customRender: (t, r, index) => parseInt(index) + 1
          },
          {
            title: '收款编号',
            align: 'center',
            dataIndex: 'relevcode',
            sorter: (a, b) => a.relevcode - b.relevcode,
          },
          {
            title: '财务组织',
            align: 'center',
            dataIndex: 'paymentCompany_dictText',
            sorter: (a, b) => a.paymentCompany_dictText - b.paymentCompany_dictText,
          },
          {
            title: '收款类型',
            align: 'center',
            dataIndex: 'typeId_dictText',
            sorter: (a, b) => a.typeId_dictText - b.typeId_dictText,
          },
          {
            title: '单据日期',
            align: 'center',
            dataIndex: 'billdate',
            customRender: function (text) {
            return !text ? '' : text.length > 10 ? text.substr(0, 10) : text
            },
            sorter: (a, b) => a.billdate - b.billdate,
          },
          {
            title: '起算日期',
            align: 'center',
            dataIndex: 'busidate',
            customRender: function (text) {
            return !text ? '' : text.length > 10 ? text.substr(0, 10) : text
            },
            sorter: (a, b) => a.busidate - b.busidate,
          },
          {
            title: '是否同步',
            align: 'center',
            dataIndex: 'isSyncNc_dictText',
            sorter: (a, b) => a.isSyncNc_dictText - b.isSyncNc_dictText,
          },
          {
            title: '用友单号',
            align: 'center',
            dataIndex: 'confimCode',
            sorter: (a, b) => a.confimCode - b.confimCode,
          },
          {
            title: '操作',
            dataIndex: 'action',
            align: 'center',
            scopedSlots: { customRender: 'action' },
          },
        ],
        // 字典选项
        dictOptions: {},
        // 展开的行
        expandedRowKeys: [],
        url: {
          list: "/online/api/listClmCollectionOrder",
          delete: "/online/api/deleteClmCollectionOrder",
          deleteBatch: "/online/api/deleteClmCollectionOrderBatch",
          exportXlsUrl: "/online/api/export/exportXlsClmCollectionOrder",
          importExcelUrl: "/online/api/import/importXlsClmCollectionOrder",
          addNcCollEstimateOrder: "/online/api/addNcCollEstimateOrder", //预估
        },
      }
    },
    computed: {
      importExcelUrl() {
        return window._CONFIG['domianURL'] + this.url.importExcelUrl
      }
    },
    methods: {

      initDictConfig() {
      },

      handleExpand(expanded, record) {
        this.expandedRowKeys = []
        if (expanded === true) {
          this.expandedRowKeys.push(record.id)
        }
      },
      async handleConfim(id){
        const res = await postAction(this.url.addNcCollEstimateOrder,{id: id});
        if (res.success) {
          this.$message.success('提交成功')
          this.loadData()
        }else{
          this.$message.error("提交失败!" + res.message)
        }
      },
    }
  }
</script>
<style lang="less" scoped>
  @import '~@assets/less/common.less';
</style>
